package com.project.market.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.project.market.service.AdminStartService;
import com.project.market.service.impl.AdminStartServiceImpl;
import com.project.market.util.JacksonUtil;
import com.project.market.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/admin/stat/*")
public class AdminStartController extends HttpServlet {

    AdminStartService adminStartService = new AdminStartServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String op = req.getRequestURI().replace(req.getContextPath() + "/admin/stat/", "");
        if ("user".equals(op)) {
            user(req,resp);
        }
    }

    private void user(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Map<Object,Object> map = adminStartService.user();

        resp.getWriter().println(JacksonUtil.writeValueAsString(ResponseUtil.ok(map)));
    }
}
